home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / Morpion 1.0.0 / source / PNL Libraries / MyAppleEvents.unit < prev    next >
Encoding:
Text File  |  1993-10-22  |  3.4 KB  |  110 lines  |  [TEXT/PJMM]

  1. unit MyAppleEvents;
  2.  
  3. interface
  4.  
  5.     function InitAppleEvents (DoOApp, DoODoc, DoPrint, DoQuit: Ptr): OSErr;
  6. { function DoOApp: OSErr }
  7. { function DoODoc (fs: FSSpec): OSErr }
  8. { function DoPrint (fs: FSSpec): OSErr }
  9. { function DoQuit: OSErr}
  10.  
  11. implementation
  12.  
  13.     uses
  14.         AppleTalk, PPCToolbox, Processes, EPPC, Notification, AppleEvents, MyAEUtils;
  15.  
  16.     function DoOApp (p: ptr): OSErr;
  17.     inline
  18.         $205F, $4E90;
  19.  
  20.     function DoDocs (fs: FSSpec; p: ptr): OSErr;
  21.     inline
  22.         $205F, $4E90;
  23.  
  24.     function DoQuit (p: ptr): OSErr;
  25.     inline
  26.         $205F, $4E90;
  27.  
  28.     const
  29.         kPatienceLevel = 1000;                                { <aevt> ticks we wait for response }
  30.         kSysEnvironsVersion = 1;
  31.         kOSEvent = app4Evt;    {event used by MultiFinder}
  32.         kSuspendResumeMessage = 1;        {high byte of suspend/resume event message}
  33.         kResumeMask = 1;        {bit of message field for resume vs. suspend}
  34.         kMouseMovedMessage = $FA;        {high byte of mouse-moved event message}
  35.         kNoEvents = 0;        {no events mask}
  36.         kNoListChosen = -1;
  37.  
  38.     function HandleOAPP (theAppleEvent, reply: AppleEvent; openappp: ptr): OSErr;{ <aevt> }
  39.         var
  40.             oe: OSErr;
  41.     begin
  42.     { We don't expect any params at all, but check in case the client requires any }
  43.         oe := GotRequiredParams(theAppleEvent);
  44.         oe := DoOApp(openappp);
  45.         HandleOAPP := oe;
  46.     end;
  47.  
  48.     function HandleDocs (theAppleEvent, reply: AppleEvent; dodocp: ptr): OSErr;        { <aevt> }
  49.         var
  50.             myFSS: FSSpec;
  51.             docList: AEDescList;
  52.             index, itemsInList: LONGINT;
  53.             actualSize: Size;
  54.             keywd: AEKeyword;
  55.             typeCode: descType;
  56.             oe, ooe: OSErr;
  57.     begin
  58.         oe := AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
  59.         if oe = noErr then begin
  60.             ooe := GotRequiredParams(theAppleEvent);
  61.     { now get each alias from the list (as an FSSSpec) and open the associated file. }
  62.             oe := AECountItems(docList, itemsInList);
  63.             for index := 1 to itemsInList do begin
  64.                 ooe := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
  65. { coercion does alias->fsspec }
  66.                 if ooe = noErr then
  67.                     ooe := DoDocs(myFSS, dodocp);
  68.             end;
  69.             ooe := AEDisposeDesc(docList);
  70.         end;
  71.         HandleDocs := oe;
  72.     end; { HandleDocs }
  73.  
  74.     function HandleQUIT (theAppleEvent, reply: AppleEvent; quitp: ptr): OSErr;        { <aevt> }
  75.         var
  76.             oe: OSErr;
  77.             errStr: Str255;
  78.     begin
  79.     { We don't expect any params at all, but check in case the client requires any }
  80.         oe := GotRequiredParams(theAppleEvent);
  81.         oe := DoQuit(quitp);            { set global boolean: app will exit at end of event loop }
  82.         if reply.dataHandle <> nil then            { a reply is sought }
  83.             begin
  84.             if oe = noErr then
  85.                 errStr := 'OK'
  86.             else
  87.                 errStr := 'user cancelled quit';
  88.             oe := AEPutParamPtr(reply, 'errs', 'TEXT', Ptr(@errStr[1]), length(errStr));
  89.         end;
  90.         HandleQUIT := oe;
  91.     end;
  92.  
  93. {$S Init}
  94.     function InitAppleEvents (DoOApp, DoODoc, DoPrint, DoQuit: Ptr): OSErr;
  95.         var
  96.             aevtErr: OSErr;
  97.     begin
  98.         aevtErr := noErr;
  99.         if (aevtErr = noErr) and (DoOApp <> nil) then
  100.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, @HandleOAPP, longInt(DoOApp), false);
  101.         if (aevtErr = noErr) and (DoODoc <> nil) then
  102.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleDocs, longInt(DoODoc), false);
  103.         if (aevtErr = noErr) and (DoPrint <> nil) then
  104.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, @HandleDocs, longInt(DoPrint), false);
  105.         if (aevtErr = noErr) and (DoQuit <> nil) then
  106.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, @HandleQUIT, longInt(DoQuit), false);
  107.         InitAppleEvents := aevtErr;
  108.     end;
  109.  
  110. end.